let html
let FileName = "read-mail"
let LogTag = {
    MdLoad: "__MdLoad"
}

/**
 * 加载内容
 * js调用原生方法:
 * CoreMail
 */
function loadContent() {
    console.log('loadContent', FileName, LogTag.MdLoad)
    const newHtml = window.CoreMail.getMdContent();
    if (!newHtml || newHtml === html) {
        return;
    }
    const $content = $('#mail-content')
        .html(html = newHtml)
    // .css('padding', window.CoreMail.getPadding());

    // 防止内容可编辑
    // $content
    //   .find('[contenteditable],[readonly]')
    //   .removeAttr('contenteditable')
    //   .removeAttr('readonly')
    //   .css('user-modify', '');

    $('a').attr('target', '');
    // notifyHeight();
}

function notifyHeight() {
    setTimeout(() => window.CoreMail.notifyHeight(document.body.offsetHeight), 200);
}

$(function () {
    window.CoreMail && window.CoreMail.ready()
    loadContent();
    $(document).on('contextmenu', function (e) {
        var url = $(e.target).closest('img').attr('src');
        window.CoreMail.contextMenu(JSON.stringify({
            hasSel: !!window.getSelection().toString(),
            imageUrl: url
        }));
    });
    window.addEventListener(
        "wheel",
        function (event) {
            if (event.ctrlKey) {
                event.preventDefault();
                event.stopPropagation();
                window.CoreMail.scrollEvent(event.deltaY > 0);
            }
        },
        { passive: false }
    );
});